import ModuleTemplate from '@/utils/ModuleTemplate';
import appService from '@/utils/appService';
import systemConfig from '@/utils/config';

/* eslint-disable */
/** modules名称空间 */
export const namespace = 'account';
const model = {
    name: namespace,
    /** 基本属性 */
    state: {
        /** 分页数据查询条件 */
        query: {
            currentPage: 1,
            pageSize: 10
        }
    },
    /** 从基本数据派生的数据,getters接收state作为其第一个参数，
     * 接受其他 getters 作为第二个参数，如不需要，第二个参数可以省略
     */
    getters: {},
    /** 执行同步操作，包含用于直接修改state的函数 */
    mutations: {
    },
    /** 异步操作，可调用同步操作函数 */
    actions: {
        // 字典
        getMerchantSearchKey(store, payload) {
            return new Promise((resolve, reject) => {
                appService.getRequest(`${config.dataSource}/admin/property/dictionary`, payload).then((result) => {
                    if (result.data.ret === 0) {
                        resolve(result);
                    } else {
                        reject(Error);
                    }
                });
            });
        },
        /** 对账配置设置 **/
        getConfigSet (store, payload) {
            return new Promise((resolve, reject) => {
                appService.getRequest(`${config.dataSource}/admin/property/list`, payload).then((result) => {
                    if (result.data.ret === 0) {
                        resolve(result);
                    } else {
                        reject(Error);
                    }
                });
            });
        },
        /** 对账配置设置- 查询有无相同费用类型 **/
        searchConfigType (store, payload) {
            return new Promise((resolve, reject) => {
                appService.getRequest(`${config.dataSource}/admin/settlement/config/queryConfig`, payload).then((result) => {
                    if (result.data.ret === 0) {
                        resolve(result);
                    } else {
                        reject(Error);
                    }
                });
            });
        },
        /** 保存对账配置 **/
        saveConfigSet(store, payload){
            return new Promise((resolve, reject) => {
                appService.postRequest(`${config.dataSource}/admin/property/batch`, payload).then((result) => {
                    if (result.data.ret === 0) {
                        resolve(result);
                    } else {
                        reject(Error);
                    }
                });
            });
        },
        /** 关联配置列表 **/
        getTableList(store, payload) {
            return new Promise((resolve, reject) => {
                appService.getRequest(`${config.dataSource}/admin/settlement/config/list`, payload).then((result) => {
                    if (result.data.ret === 0) {
                        resolve(result);
                    } else {
                        reject(result);
                    }
                });
            });
        },
        /** 保存关联配置 **/
        saveRelevanceConfig(store, payload) {
            return new Promise((resolve, reject) => {
                appService.postRequest(`${config.dataSource}/admin/settlement/config/`, payload).then((result) => {
                    if (result.data.ret === 0) {
                        resolve(result);
                    } else {
                        reject(result);
                    }
                });
            });
        },
        /** 更新关联配置 **/
        upDataRelevanceConfig(store, payload) {
            return new Promise((resolve, reject) => {
                appService.putRequest(`${config.dataSource}/admin/settlement/config/`, payload).then((result) => {
                    if (result.data.ret === 0) {
                        resolve(result);
                    } else {
                        reject(result);
                    }
                });
            });
        },
        /** 删除关联配置 **/
        deleteRelevanceConfig(store, payload) {
            return new Promise((resolve, reject) => {
                appService.deleteRequest(`${config.dataSource}/admin/settlement/config/${payload}`).then((result) => {
                    if (result.data.ret === 0) {
                        resolve(result);
                    } else {
                        reject(result);
                    }
                });
            });
        },

    },
    /** 子模块 */
    modules: {}
};
const config = {
    /** 数据源，对应后端controller类的请求映射,
     * 如果不指定则默认和name一样
     */
    /* eslint-disable */
    dataSource: systemConfig.serverProxy + '/trade-settlement',
    // dataSource: systemConfig.tradeInvoicePath,
    invoiceServer: true,
    /** query函数调用的后端controller方法的请求映射 */
    queryMethod: null,
    updateMethod: null,
    deleteMethod: null,
    saveMethod: null,
    getDetailMethod: null
};
const moduleTemplate = new ModuleTemplate(model, config);
export const module = moduleTemplate.createModel();
